/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package imp.command;

import dom.command.Command;
import dom.command.Result;
import dom.command.Status;
import imp.reciever.scriptexecuter.ScriptExecuter;

/**
 * ExecuteScript executes a script, which
 * can be a .bat or .sh depending on the
 * reciever
 * @author julian.pena
 */
public class ExecuteScript implements Command{

    private final CommandType commandType = CommandType.EXECUTE_SCRIPT;
    private Status status;
    private Result result;
    /**
     * The entity who executes a
     * type of script
     */
    private ScriptExecuter executer;
    //<editor-fold defaultstate="collapsed" desc="costructors">
    public ExecuteScript(ScriptExecuter executer) {
        this.executer = executer;
        this.status = Status.NOT_STARTED;
    }
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="methods">
    @Override
    public void execute() {
        try {
            status = Status.IN_PROGRESS;
            executer.action();
            status = Status.FINISHED;
            result = Result.SUCCESSFUL;
        } catch (Exception ex) {
            status = Status.FINISHED;
            result = Result.FAILED;
            System.out.println(ex.getMessage());
        }
    }
    
    @Override
    public void run() {
        execute();
    }
    
    @Override
    public Status getStatus() {
        return status;
    }
    
    @Override
    public Result getResult() {
        return result;
    }
    
    @Override
    public String getName() {
        return commandType.getStringValue();
    }
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="getters and setters">
    
    
    
    //</editor-fold>

}
